package com.example.javabasic.jvm;

import java.io.FileNotFoundException;

/**
 * 自定义ClassLoader
 */
public class CustomClassLoader extends java.lang.ClassLoader {

    @Override
    protected Class<?> findClass(String name)throws ClassNotFoundException{
        try {
            byte[] result = getClassFromCustomPath(name);
            if(result== null){
                throw new FileNotFoundException();
            }else{
                return defineClass(name,result,0,result.length);
            }

        }catch(FileNotFoundException e){
            e.printStackTrace();
        }
        return null;

    }

    private byte[] getClassFromCustomPath(String name) {
        //从自定义路径中加载指定类
        //如果字节码文件有加密解密操作  可以从这里加入对应的逻辑
        return null;
    }
}
